package com.hsd.znsh.converter;

import com.hsd.znsh.entity.Batch;
import com.hsd.znsh.entity.Host;
import com.hsd.znsh.enums.BatchStatusEnum;
import com.hsd.znsh.pojo.output.BatchVO;
import com.hsd.znsh.repository.HostRepository;
import com.hsd.znsh.utils.BeanUtil;
import com.hsd.znsh.utils.EnumUtil;

import java.util.ArrayList;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-26 14:48:19
 */
public class BatchConverter {

    public static BatchVO converterToBachVO(Batch batch, HostRepository hostRepository){
        BatchVO batchVO=new BatchVO();
        BeanUtil.copyProperties(batch,batchVO);

        if(batch.getHostId()!=null){
            Host host=hostRepository.findOne(batch.getHostId());
            batchVO.setHostName(host.getHostName());
            batchVO.setHostSn(host.getHostSn());
        }
        batchVO.setStatusName(EnumUtil.getMessageByCode(batch.getStatus(), BatchStatusEnum.class));
        return  batchVO;
    }

    public static BatchVO converterToBachVO(Batch batch){
        BatchVO batchVO=new BatchVO();
        BeanUtil.copyProperties(batch,batchVO);
        batchVO.setStatusName(EnumUtil.getMessageByCode(batch.getStatus(), BatchStatusEnum.class));
        return  batchVO;
    }

    public static List<BatchVO> converterToBachVOList(List<Batch> batchs, HostRepository hostRepository){
        List<BatchVO> list=new ArrayList<>();
        for(Batch batch:batchs){
            list.add(converterToBachVO(batch,hostRepository));
        }
        return  list;
    }

    public static List<BatchVO> converterToBachVOList(List<Batch> batchs){
        List<BatchVO> list=new ArrayList<>();
        for(Batch batch:batchs){
            list.add(converterToBachVO(batch));
        }
        return  list;
    }
}
